﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<TPOJ.Model.Contest>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%= Html.Encode(Model.Title) %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" >
    $().ready(function () {
        var iid = setInterval(updateTimer,1000);
    });

    function updateTimer() {
        var start = new Date($("#start").text());
        var current = new Date($("#currentTime").val());
        var end = new Date($("#end").text());
        if (start > current) {
            $("#timer").text("Contest hasn't started.");
        } else {
            if (current > end) {
                $("#timer").text("Contest is over.");
            } else {
                $("#timer").text("TO-DO:A timer here.");
            }
        }
    }
</script>
    <h1><%= Html.Encode(Model.Title) %></h1>
    <br />
    <p><%= Html.Encode(Model.Description) %></p>
    <br />
        <div class="facts">
            <table>
                <tr>
                    <td>
                        <b>Start Time:</b>
                        <span id="start"><%= Html.Encode(String.Format("{0:g}", Model.StartTime)) %></span>
                    </td>
                    <td class="span">
                    </td>
                    <td>
                        <b>End Time:</b>
                        <span id="end"><%= Html.Encode(String.Format("{0:g}", Model.EndTime)) %></span>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <b><label id="timer"></label><%=Html.Hidden("currentTime", ViewData["current"].ToString()) %></b>                        
                    </td>
                </tr>
            </table>
        </div>
        <p />
       <table>
        <tr>        
        <% if (Request.IsAuthenticated) { %>
        <th></th>
        <% } %>
            <th></th>
            <th>
                ID
            </th>
            <th>
                Title
            </th>
        </tr>
        
    <% IList<int> solvedIds = new List<int>();
            IList<int> triedIds = new List<int>(); %>
    <% if (Request.IsAuthenticated) { solvedIds = (IList<int>)ViewData["SolvedIds"]; triedIds = (IList<int>)ViewData["TriedIds"]; } %>
    <% int i = -1; %>
    <% foreach (var item in Model.Problems.OrderBy(p=>p.UniqueID)) { %>
    <% i++; %>
        <tr>        

            <% if (Request.IsAuthenticated) { %>
        <td>
            <% if (solvedIds.Contains(item.UniqueID)) { %>
                <img src="..\..\Content\Solved.png" alt="solved"/>
            <% } else {
                   if (triedIds.Contains(item.UniqueID)) { %>
                <img src="..\..\Content\Tried.png" alt="Tried" />
                <% } %>
            <% } %>
        </td>
        <% } %>

            <td><%= Html.Encode(Convert.ToChar('A' + i)) %></td>
            <td>
                <%= Html.Encode(item.UniqueID) %>
            </td>
            <td>
            <%= Html.ActionLink(item.Title, "Details", "Problem", new { id = item.UniqueID, contestId = Model.UniqueID }, new { target = "_blank" })%>
            </td>
        </tr>
    
    <% } %>

    </table> 

    <fieldset>
        <legend>Features</legend>
        [<%= Html.ActionLink("Standing", "Standing", "Contest", new { id = Model.UniqueID }, new { target = "_blank" })%>]
        [<%= Html.ActionLink("Status", "Status", "Contest", new { id = Model.UniqueID }, new { target = "_blank" })%>]    
        [<%= Html.ActionLink("Statistics", "Statistics", "Contest", new { id = Model.UniqueID }, new { target = "_blank" })%>]
        </fieldset>
</asp:Content>

